package com.beyond.market.orders.controller;

import com.beyond.market.orders.domain.OrderDetails;
import com.beyond.market.orders.service.CreateOrderService;
import com.beyond.market.orders.service.OrderDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class CreateOrdersController {
    @Autowired
    private CreateOrderService createOrderService;
    @Autowired
    private OrderDetailsService orderDetailsService;
    @RequestMapping("/createOrders")
    @ResponseBody
    public String createOrders(List<Integer> list){
        try {
            createOrderService.createOrder(list);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return "yes";
    }
    @RequestMapping("/listById")
    public String listById(@RequestParam("id") int id, Map<String,Object> map3) throws SQLException {
        try {
            List<OrderDetails> list = orderDetailsService.listById(id);
            map3.put("ods",list);
        } catch (SQLException e) {
            e.printStackTrace();

        }
        return "orderDetails";
    }

}
